import json
from pathlib import Path
import plotly.express as px

path = Path('eq_data/eq_data_1_day_m1.geojson')
contents = path.read_text()
all_eq_data = json.loads(contents)

# path=Path('eq_data/readable_eq_data.geojson')
# readable_contents=json.dumps(all_eq_data,indent=4)
# path.write_text(readable_contents)

all_eq_dicts = all_eq_data['features']
print(len(all_eq_dicts))
mags, titles, lons, lats = [], [], [], []
for eq_dic in all_eq_dicts:
    mag = eq_dic['properties']['mag']
    title = eq_dic['properties']['title']
    lon = eq_dic['geometry']['coordinates'][0]
    lat = eq_dic['geometry']['coordinates'][1]
    mags.append(mag)
    titles.append(title)
    lons.append(lon)
    lats.append(lat)
print(mags[:10])
print(titles[:2])
print(lons[:5])
print(lats[:5])

fig = px.scatter(x=lons, y=lats, labels={'x': '经度', 'y': '维度'},
                 range_x=[-200, 200],
                 range_y=[-90, 90],
                 width=800, height=800,
                 title='全球地震散点图',
                 size='震级',
                 size_max=10)
fig.write_html('global_eq.html')
fig.show()
